-- 2018-12-03 新增数据权限表
CREATE TABLE [dbo].[th_SysDataPermission] (
[DataPerGUID] uniqueidentifier NOT NULL ,
[DataPerType] varchar(50) COLLATE Chinese_PRC_CI_AS NULL ,
[Dimension] varchar(10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[ObjectGUID] uniqueidentifier NULL ,
CONSTRAINT [PK__th_SysDa__1D3E7B973A798BC8] PRIMARY KEY ([DataPerGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysDataPermission', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'数据权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'数据权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysDataPermission', 
'COLUMN', N'DataPerGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysDataPermission', 
'COLUMN', N'DataPerType')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'数据权限类型:project-项目'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerType'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'数据权限类型:project-项目'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerType'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysDataPermission', 
'COLUMN', N'Dimension')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'授权维度:group-全集团,bu-本公司,current-本项目'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'Dimension'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'授权维度:group-全集团,bu-本公司,current-本项目'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'Dimension'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysDataPermission', 
'COLUMN', N'ObjectGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'业务GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'ObjectGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'业务GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysDataPermission'
, @level2type = 'COLUMN', @level2name = N'ObjectGUID'
GO

-- 2018-12-03 新增功能权限表
CREATE TABLE [dbo].[th_SysPermission] (
[PerGUID] uniqueidentifier NOT NULL ,
[PerName] varchar(50) COLLATE Chinese_PRC_CI_AS NULL ,
[PerCode] varchar(50) COLLATE Chinese_PRC_CI_AS NULL ,
[Type] int NULL DEFAULT ((0)) ,
[Url] varchar(255) COLLATE Chinese_PRC_CI_AS NULL ,
[ParentGUID] uniqueidentifier NULL ,
[Level] int NULL ,
CONSTRAINT [PK__th_SysDa__B069CA1C2FFBFD55] PRIMARY KEY ([PerGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'功能权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'功能权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'PerGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'功能GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'功能GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'PerName')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'功能名称'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerName'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'功能名称'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerName'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'PerCode')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'功能权限code'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerCode'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'功能权限code'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'PerCode'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'Type')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'0-菜单，1-按钮'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Type'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'0-菜单，1-按钮'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Type'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'Url')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'请求Url'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Url'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'请求Url'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Url'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'ParentGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'父级GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'ParentGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'父级GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'ParentGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysPermission', 
'COLUMN', N'Level')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'等级'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Level'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'等级'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysPermission'
, @level2type = 'COLUMN', @level2name = N'Level'
GO

-- 2018-12-03 新增角色表
CREATE TABLE [dbo].[th_SysRole] (
[RoleGUID] uniqueidentifier NOT NULL ,
[RoleName] varchar(50) COLLATE Chinese_PRC_CI_AS NULL ,
[RoleType] tinyint NULL ,
[remark] varchar(200) COLLATE Chinese_PRC_CI_AS NULL ,
[ParentRoleGUID] uniqueidentifier NULL ,
[Level] int NULL ,
CONSTRAINT [PK__SysRole__D10427771FC5958C] PRIMARY KEY ([RoleGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'RoleGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'RoleName')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色名称'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleName'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色名称'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleName'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'RoleType')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色类型'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleType'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色类型'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'RoleType'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'remark')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'备注'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'remark'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'备注'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'remark'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'ParentRoleGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'父级角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'ParentRoleGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'父级角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'ParentRoleGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRole', 
'COLUMN', N'Level')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'层级树'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'Level'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'层级树'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRole'
, @level2type = 'COLUMN', @level2name = N'Level'
GO

-- 2018-12-03 新增角色功能权限表
CREATE TABLE [dbo].[th_SysRolePermission] (
[RolePermissionGUID] uniqueidentifier NOT NULL ,
[RoleGUID] uniqueidentifier NULL ,
[PermissionGUID] uniqueidentifier NULL ,
CONSTRAINT [PK__SysRoleD__10E9B04F2766B754] PRIMARY KEY ([RolePermissionGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRolePermission', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色功能权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色功能权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRolePermission', 
'COLUMN', N'RolePermissionGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'RolePermissionGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'RolePermissionGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRolePermission', 
'COLUMN', N'RoleGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysRolePermission', 
'COLUMN', N'PermissionGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'PermissionGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysRolePermission'
, @level2type = 'COLUMN', @level2name = N'PermissionGUID'
GO

-- 2018-12-03 新增用户数据权限表
CREATE TABLE [dbo].[th_SysUserDataPermission] (
[UserDataPerGUID] uniqueidentifier NOT NULL ,
[UserGUID] uniqueidentifier NULL ,
[DataPerGUID] uniqueidentifier NULL ,
CONSTRAINT [PK__SysPermi__BE2E30D72B374838] PRIMARY KEY ([UserDataPerGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserDataPermission', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户数据权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户数据权限表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserDataPermission', 
'COLUMN', N'UserDataPerGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'UserDataPerGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'UserDataPerGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserDataPermission', 
'COLUMN', N'UserGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserDataPermission', 
'COLUMN', N'DataPerGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'数据权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserDataPermission'
, @level2type = 'COLUMN', @level2name = N'DataPerGUID'
GO

-- 2018-12-03 用户功能权限关联表
CREATE TABLE [dbo].[th_SysUserPermission] (
[UserPerGUID] uniqueidentifier NOT NULL ,
[UserGUID] uniqueidentifier NULL ,
[PermissionGUID] uniqueidentifier NULL ,
CONSTRAINT [PK__th_SysFu__321A014433CC8E39] PRIMARY KEY ([UserPerGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserPermission', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户功能权限关联表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户功能权限关联表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserPermission', 
'COLUMN', N'UserPerGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'UserPerGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'UserPerGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserPermission', 
'COLUMN', N'UserGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserPermission', 
'COLUMN', N'PermissionGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'PermissionGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'权限GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserPermission'
, @level2type = 'COLUMN', @level2name = N'PermissionGUID'
GO

-- 2018-12-03 角色用户关联表
CREATE TABLE [dbo].[th_SysUserRole] (
[RoleUserGUID] uniqueidentifier NOT NULL ,
[RoleGUID] uniqueidentifier NULL ,
[UserGUID] uniqueidentifier NULL ,
[BUGUID] uniqueidentifier NULL ,
CONSTRAINT [PK__SysRoleU__7C31A27C23962670] PRIMARY KEY ([RoleUserGUID])
)
ON [PRIMARY]
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserRole', 
NULL, NULL)) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色用户关联表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色用户关联表'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserRole', 
'COLUMN', N'RoleUserGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'RoleUserGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'RoleUserGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserRole', 
'COLUMN', N'RoleGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'角色GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'RoleGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserRole', 
'COLUMN', N'UserGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'UserGUID'
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'th_SysUserRole', 
'COLUMN', N'BUGUID')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'单位GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'BUGUID'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'单位GUID'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'th_SysUserRole'
, @level2type = 'COLUMN', @level2name = N'BUGUID'
GO